﻿using System;
using System.Text;

namespace Ayatta.Contract.Domain
{

    #region AuthSms
    /// <summary>
    /// 短信验证
    /// </summary>
    public class AuthSms : BaseEntity<string>
    {
        /// <summary>
        /// 0为注册验证码 1为手机绑定验证 2为通过手机重置密码验证
        /// </summary>
        /// <value></value>
        public int Group { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string Mobile { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public int UserId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string Code { get; set; }

        /// <summary>
        /// 状态 1成功消费 0初始
        /// </summary>
        public bool Status { get; set; }

        /// <summary>
        /// 生成20位随机字符做为Id
        /// </summary>
        public static string NewCode()
        {
            const string str = "0123456789";

            var sb = new StringBuilder();

            var b = new byte[4];
            new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b);
            var r = new Random(BitConverter.ToInt32(b, 0));

            for (var i = 0; i < 6; i++)
            {
                sb.Append(str.Substring(r.Next(0, str.Length - 1), 1));
            }
            return sb.ToString();
        }
    }

    #endregion

}